package edu.fim.presentation.model.bean;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import edu.fim.data.Identifiable;

@Entity
@Table(name = "tb_consumers")
public class Consumer implements Identifiable<Integer> {

	private static final long serialVersionUID = 4851042718844931236L;

	private Integer id;
	private String name;
	private Integer age;
	private Double height;
	private Double weight;
	private Double consumedCalories;
	private Double caloriesThreshold;
	private String username;
	private String password;
	private List<Food> preferences;
	private List<Meal> meals;

	public Consumer() {
	}

	public Consumer(Integer id, String name, Integer age, Double height,
			Double weight, Double consumedCalories, Double caloriesThreshold) {
		this.id = id;
		this.name = name;
		this.age = age;
		this.height = height;
		this.weight = weight;
		this.consumedCalories = consumedCalories;
		this.caloriesThreshold = caloriesThreshold;
	}

	@Id
	@Column(name = "id")
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "age")
	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	@Column(name = "height")
	public Double getHeight() {
		return height;
	}

	public void setHeight(Double height) {
		this.height = height;
	}

	@Column(name = "weight")
	public Double getWeight() {
		return weight;
	}

	public void setWeight(Double weight) {
		this.weight = weight;
	}

	@Column(name = "consumedCalories")
	public Double getConsumedCalories() {
		return consumedCalories;
	}

	public void setConsumedCalories(Double consumedCalories) {
		this.consumedCalories = consumedCalories;
	}

	@Column(name = "caloriesThreshold")
	public Double getCaloriesThreshold() {
		return caloriesThreshold;
	}

	public void setCaloriesThreshold(Double caloriesTheshold) {
		this.caloriesThreshold = caloriesTheshold;
	}

	@Column(name = "username")
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@Column(name = "password")
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@ManyToMany
	@JoinTable(
			name = "tb_preferences",
			joinColumns = { @JoinColumn(name = "idConsumer") },
			inverseJoinColumns = { @JoinColumn(name = "idFood") }
	)
	public List<Food> getPreferences() {
		return preferences;
	}

	public void setPreferences(List<Food> preferences) {
		this.preferences = preferences;
	}
	
	@OneToMany(targetEntity = Meal.class, mappedBy = "consumer")
	public List<Meal> getMeals() {
		return meals;
	}

	public void setMeals(List<Meal> meals) {
		this.meals = meals;
	}
	
	public void add(Food preference) {
		preferences.add(preference);
	}
	
	public void remove(Food preference) {
		preferences.remove(preference);
	}

	@Override
	public String toString() {
		return id + ": " + name;
	}
}